'''
Created on Dec 22, 2013

@author: Justin
'''

from src.world import World


class Mobile:

  def __init__(self):

    self.hp = {"current": 0,
               "max": 0}
    self.name = None
    self.location = None
    self.attrs = set()
    self.UID = self._generateUID()

  def _getWorldList(self):
    
    world_list = None
    if "player" in self.attrs:
      world_list = World.players
    elif "mob" in self.attrs:
      world_list = World.mobs
    return world_list

  def _generateUID(self):
    
    total_obj = len(World.players) + \
                len(World.mobs) + \
                len(World.items)
    for n in xrange(total_obj):
      if n not in World.uid_list:
        World.uid_list.add(n)
        return n
    World.uid_list.add(total_obj + 1)
    return total_obj + 1

  def loadToWorld(self):

    self._getWorldList()[self.UID] = self

  def removeFromWorld(self):

    self._getWorldList().pop(self.UID)

  def getStringLocation(self):

    return str(self.location)

  def move(self, new_loc):

    destination = World.rooms.get(str(new_loc))
    current_location = World.rooms.get(self.getStringLocation())
    if current_location:
      current_location.removeObj(self)
    if destination:
      destination.addObj(self)
      self.location = destination.coords

  def hear(self, msg = None):
    pass
